package com.movil.registrodelapropiedadgt;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import consultaADistancia.Show_Documento;

import android.R.integer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class PruebaWS1 extends Activity implements OnClickListener {
	//
	private static final String SOAP_ACTION = "http://ejbs/DoctoTramite";
	private static final String METHOD_NAME = "DoctoTramite";
	private static final String NAMESPACE = "http://ejbs/";
	private static final String URL = "http://172.16.0.188:9080/ServiciosPublicosWeb/services/Movil?wsdl";
	
	final HttpTransportSE transporte = new HttpTransportSE(URL);
	
	//public SoapPrimitive resultString = null;
	
	TextView TV_WebServicews1;
	Button BT_ComunicarWS;
	EditText ET_numero;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_prueba_ws1);
		
		TV_WebServicews1=(TextView)findViewById(R.id.LTV_PruebaWS1);
		ET_numero=(EditText)findViewById(R.id.LET_numeroWS);
		BT_ComunicarWS=(Button)findViewById(R.id.LBT_PruebaWS1);
		BT_ComunicarWS.setOnClickListener(this);
		
		conasync objcon =new conasync();
		objcon.execute("");
		
		//comunicarWS();
		
	}
///////////////////////////////////////////////
	public void comunicarWS(){

		try {
			int a = Integer.parseInt("12");
			
			TV_WebServicews1.setText("Esperando respuesta");
			
			SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
			HttpTransportSE transporte = new HttpTransportSE(URL);
			Request.addProperty("propID","13R1231231");

			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			//soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(Request);
			transporte.call(SOAP_ACTION, soapEnvelope);
		/*	 resultString = (SoapPrimitive) soapEnvelope.getResponse();
			System.out.println(resultString.toString());
			TV_WebServicews1.setText(resultString.toString());*/
			// //////////////////////////
		} catch (Exception e) {
			System.out.println("error en la conexion " + e.getMessage());

		}

	
	}
	public void comunicarWS(int celsius){

		try {
			int a = Integer.parseInt("12");
			
			TV_WebServicews1.setText("Esperando respuesta");
			
			SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
			HttpTransportSE transporte = new HttpTransportSE(URL);
			Request.addProperty("propID","13R1231231");

			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			//soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(Request);
			transporte.call(SOAP_ACTION, soapEnvelope);
			/* resultString = (SoapPrimitive) soapEnvelope.getResponse();
			System.out.println(resultString.toString());
			TV_WebServicews1.setText(resultString.toString());*/
			// //////////////////////////
		} catch (Exception e) {
			System.out.println("error en la conexion " + e.getMessage());

		}
	
	}

	
	

///////////////////////////////////////////////
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.prueba_ws1, menu);
		return true;
	}
@Override
public void onClick(View v) {
	switch (v.getId()) 
	{
	
		case R.id.LBT_PruebaWS1:
			
			comunicarWS(Integer.parseInt(ET_numero.getText().toString()));
			
		break;
		
		
	}

	// TODO Auto-generated method stub
	
}


private ProgressDialog pd = null;

public class conasync extends AsyncTask<String, String, String> {

	@Override
	protected void onPreExecute() {
		pd = new ProgressDialog(PruebaWS1.this);
		pd.setTitle("Titulo");
		pd.setMessage("Procesando, por favor espere....");
		pd.setCancelable(false);
		pd.setIndeterminate(true);
		pd.show();
	}

	public SoapPrimitive resultString = null;

	protected void onPostExecute() {
		if (pd != null) {
			pd.dismiss();
		}
	}

	@Override
	protected String doInBackground(String... arg0) {
		// TODO Auto-generated method stub

		try {
			
			
			TV_WebServicews1.setText("Esperando respuesta");
			
			SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
			HttpTransportSE transporte = new HttpTransportSE(URL);
			Request.addProperty("propID","13R1231231");

			SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
					SoapEnvelope.VER11);
			//soapEnvelope.dotNet = true;
			soapEnvelope.setOutputSoapObject(Request);
			transporte.call(SOAP_ACTION, soapEnvelope);
			resultString = (SoapPrimitive) soapEnvelope.getResponse();
			System.out.println(resultString.toString());
			TV_WebServicews1.setText(resultString.toString());
			
			// //////////////////////////
		} catch (Exception e) {
			System.out.println("error en la conexion " + e.getMessage());

		}
		return null;
	}

	public void funcionCallback(String json) {

	}
}

}
